package com.app.milkteaapp.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.app.milkteaapp.activity.BalanceActivity;
import com.app.milkteaapp.activity.RechargeActivity;
import com.app.milkteaapp.activity.UpdateUserActivity;
import com.app.milkteaapp.bean.LoginGsonBean;
import com.app.milkteaapp.R;
import com.app.milkteaapp.utils.MyTools;
import com.app.milkteaapp.utils.SpUtils;

/**
 * A simple {@link Fragment} subclass.
 */
public class UserFragment extends Fragment implements View.OnClickListener{


    private TextView tvUsername;
    private TextView tvEmail;
    private TextView tvSex;
    private TextView tvMoney;
    private TextView tvUpdateUser;
    private TextView tvPhone;
    private TextView tvRecharge;
    private LoginGsonBean.User user;
    private Intent intent;

    public UserFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_user, container, false);
        tvRecharge = view.findViewById(R.id.tv_recharge);
        tvUsername = view.findViewById(R.id.tv_username_user);
        tvSex = view.findViewById(R.id.tv_sex_user);
        tvPhone = view.findViewById(R.id.tv_phone_user);
        tvEmail = view.findViewById(R.id.tv_email_user);
        user = SpUtils.getUserBean(getContext());
        tvUpdateUser = view.findViewById(R.id.tv_update_user);
        tvMoney = view.findViewById(R.id.tv_money);

        tvRecharge.setOnClickListener(this);
        tvUpdateUser.setOnClickListener(this);
        tvMoney.setOnClickListener(this);

        setTextView();
        return view;
    }

    public void setTextView() {
        tvUsername.setText(user.getName());
        tvPhone.setText(user.getPhone());
        tvEmail.setText(user.getEmail());
        tvSex.setText(MyTools.intToSex(Integer.parseInt(user.getSex())));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //点击充值按钮后
            case R.id.tv_recharge:
                intent = new Intent(getActivity(), RechargeActivity.class);
                startActivity(intent);
                break;
            //点击查询余额后
            case R.id.tv_money:
                intent = new Intent(getActivity(), BalanceActivity.class);
                startActivity(intent);
                break;
            //点击修改个人资料后
            case R.id.tv_update_user:
                intent = new Intent(getActivity(), UpdateUserActivity.class);
                startActivity(intent);
                break;
        }
    }
}
